/***********************************************************************************
@file   
@author
@attention
***********************************************************************************/
#include "Button.h"

/***********************************************************************************
\brief ：
***********************************************************************************/
button_device_s button1;
button_device_s button2;
button_device_s button3;
/***********************************************************************************
\brief ：全局化参数
***********************************************************************************/
void button_scan(void)
{
    static uint64_t cnt;   
    if(++cnt<100)//开机防止进入密码输入界面
    {return;}
	button1.value = BUTTON1;
	button2.value = BUTTON2;
	button3.value = BUTTON3;

	button_check(&button1);
	button_check(&button2);
	button_check(&button3);
} 
/***********************************************************************************
\brief ：
***********************************************************************************/
void button_check(button_device_s* button_x)
{
    if(button_x->value==BUTTON_SET)
    {
        button_x->cnt = 0;
        button_x->lock = BUTTON_LOCK_RESET;
    }
    else if(button_x->lock==BUTTON_LOCK_RESET)//关闭自锁，防止按键按住不抬起
    {
        
        button_x->cnt++;
        if(button_x->cnt>=BUTTON_INTERVAL)//10ms
        {
            button_x->cnt = 0;
            button_x->lock = BUTTON_LOCK_SET;
            button_x->flag = BUTTON_FLAG_SET;
        }
    }
}
/***********************************************************************************
\brief ：
***********************************************************************************/
void button_run(void)
{
	if(button1.flag)
	{
        activity=0;
        dead_time=0;
        sleep_device_operation_time(IR_NORMAL_TIME); 
        printf("button 1\r\n");
		button1.flag = BUTTON_FLAG_RESET;
        if(display_page==PAGE_DIS_MAIN)
        {    
           if(status==6)//测试中按功能键退出
            infrared_total(KEY_QUIT);    
           else
            infrared_total(BUT_FUNC); 
        }
        else
        {
          infrared_total(KEY_OK);    
        }
            
	}

    if(button2.flag)
	{
        activity=0;
        dead_time=0;
        sleep_device_operation_time(IR_NORMAL_TIME);
        printf("button 2\r\n");
		button2.flag = BUTTON_FLAG_RESET;
        infrared_total(KEY_RIGHT);
	}

	
    if(button3.flag)
	{
        activity=0;
        dead_time=0;
        sleep_device_operation_time(IR_NORMAL_TIME);
        printf("button 3\r\n");
		button3.flag = BUTTON_FLAG_RESET;
        infrared_total(KEY_UP);
        
	}
} 






